﻿/*
 * lcd.h
 *
 * Created: 2014-03-10 22:56:21
 *  Author: Michał
 */ 


#ifndef LCD_H_
#define LCD_H_
#include <util/delay.h>

#define LCD_RS_PORT		PORTC
#define LCD_RS_DDR		DDRC
#define LCD_RS_PIN		PORTC2
#define LCD_RS_HIGH		LCD_RS_PORT |= (1<<LCD_RS_PIN)
#define LCD_RS_LOW		LCD_RS_PORT &= ~(1<<LCD_RS_PIN)
#define LCD_RS_PULSE	LCD_RS_HIGH; LCD_RS_LOW;

#define LCD_SI_PORT		PORTC
#define LCD_SI_DDR		DDRC
#define LCD_SI_PIN		PORTC2
#define LCD_SI_HIGH		LCD_SI_PORT |= (1<<LCD_SI_PIN)
#define LCD_SI_LOW		LCD_SI_PORT &= ~(1<<LCD_SI_PIN)
#define LCD_SI_PULSE	LCD_SI_HIGH; LCD_SI_LOW;

#define CLK_PORT			PORTC
#define CLK_DDR				DDRC
#define CLK_PIN				PINC1
#define CLK_HIGH			CLK_PORT |= (1<<CLK_PIN)
#define CLK_LOW				CLK_PORT &= ~(1<<CLK_PIN)
#define CLK_PULSE			CLK_HIGH; CLK_LOW;


#define LCD_ENABLE_PORT		PORTC
#define LCD_ENABLE_DDR		DDRC
#define LCD_ENABLE_PIN		PORTC3
#define LCD_ENABLE_HIGH		LCD_ENABLE_PORT |= (1<<LCD_ENABLE_PIN)
#define LCD_ENABLE_LOW		LCD_ENABLE_PORT &= ~(1<<LCD_ENABLE_PIN)
#define LCD_ENABLE_PULSE	LCD_ENABLE_HIGH; LCD_ENABLE_LOW;


/* HD44780 Commands --------------------------------------------------------*/
#define HD44780_CLEAR					0x01
#define HD44780_HOME					0x02

#define HD44780_ENTRY_MODE				0x04
#define HD44780_EM_SHIFT_CURSOR			0x00
#define HD44780_EM_SHIFT_DISPLAY		0x01
#define HD44780_EM_DECREMENT			0x00
#define HD44780_EM_INCREMENT			0x02

#define HD44780_DISPLAY_ONOFF			0x08
#define HD44780_DISPLAY_OFF				0x00
#define HD44780_DISPLAY_ON				0x04
#define HD44780_CURSOR_OFF				0x00
#define HD44780_CURSOR_ON				0x02
#define HD44780_CURSOR_NOBLINK			0x00
#define HD44780_CURSOR_BLINK			0x01

#define HD44780_DISPLAY_CURSOR_SHIFT	0x10
#define HD44780_SHIFT_CURSOR			0x00
#define HD44780_SHIFT_DISPLAY			0x08
#define HD44780_SHIFT_LEFT				0x00
#define HD44780_SHIFT_RIGHT				0x04

#define HD44780_FUNCTION_SET			0x20
#define HD44780_FONT5x7					0x00
#define HD44780_FONT5x10				0x04
#define HD44780_ONE_LINE				0x00
#define HD44780_TWO_LINE				0x08
#define HD44780_4_BIT					0x00
#define HD44780_8_BIT					0x16

#define HD44780_CGRAM_SET				0x40

#define HD44780_DDRAM_SET				0x80


void LCD_Init(void);
void LCD_Send_Data(char data);
void LCD_Send_Commend(char);
void LCD_Send_Char(char);
void LCD_Text(char*);
void LCD_Clear(void);
void LCD_Home(void);
void LCD_Position_LN(uint8_t x, uint8_t y);

#endif /* LCD_H_ */